﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2011
// admin@franknagl.de
//
namespace SBIP.Helper
{
    using System.Drawing;
    using Microsoft.Xna.Framework;
    using DotNetColor = System.Drawing.Color;
    using Point = System.Drawing.Point;
    using XnaColor = Microsoft.Xna.Framework.Color;
    using XnaPoint = Microsoft.Xna.Framework.Point;

    /// <summary>Helper class to convert XNA types into standard Dotnet types.
    /// </summary>
    public static class XNATypesConverter
    {
        #region public methods

        /// <summary>
        /// Converts a .Net color to XNA color.
        /// </summary>
        /// <param name="color">.Net color to convert.</param>
        /// <returns>The created XNA color.</returns>
        public static XnaColor DotNetToXnaColor(DotNetColor color)
        {
            return new XnaColor(
                color.R,
                color.G,
                color.B,
                color.A);
        }

        /// <summary> Converts a specified <see cref="Point"/> type into 
        /// XNA <see cref="XnaPoint"/> type.
        /// </summary>
        /// <param name="point">
        /// The XNA <see cref="Point"/> type to convert.
        /// </param>
        /// <returns>The converted <see cref="XnaPoint"/> type.</returns>
        public static XnaPoint PointToXnaPoint(Point point)
        {
            XnaPoint pt = new XnaPoint(point.X, point.Y);
            return pt;
        }

        /// <summary> Converts a specified XNA <see cref="Vector2"/> type into
        /// <see cref="Point"/> type.
        /// </summary>
        /// <param name="vector2">
        /// The XNA <see cref="Vector2"/> type to convert.
        /// </param>
        /// <returns>The converted <see cref="Point"/> type.</returns>
        public static Point Vector2ToPoint(Vector2 vector2)
        {
            Point pt = new Point(
                (int)(vector2.X + 0.5f), (int)(vector2.Y + 0.5f));

            return pt;
        }

        /// <summary>
        /// Converts a specified XNA <see cref="Vector2"/> type into
        /// <see cref="Point"/> type.
        /// </summary>
        /// <param name="vector2">
        /// The XNA <see cref="Vector2"/> type to convert.</param>
        /// <param name="point">The converted <see cref="Point"/> type.</param>
        public static void Vector2ToPoint(Vector2 vector2, out Point point)
        {
            point = Vector2ToPoint(vector2);
        }

        /// <summary> Converts a specified XNA <see cref="Vector2"/> type into
        /// <see cref="PointF"/> type.
        /// </summary>
        /// <param name="vector2">
        /// The XNA <see cref="Vector2"/> type to convert.
        /// </param>
        /// <returns>The converted <see cref="PointF"/> type.</returns>
        public static PointF Vector2ToPointF(Vector2 vector2)
        {
            PointF pt = new PointF(vector2.X, vector2.Y);
            return pt;
        }

        /// <summary>
        /// Converts a specified XNA <see cref="Vector2"/> type into
        /// <see cref="Point"/> type.
        /// </summary>
        /// <param name="vector2">
        /// The XNA <see cref="Vector2"/> type to convert.</param>
        /// <param name="point">The converted <see cref="Point"/> type.</param>
        public static void Vector2ToPointF(Vector2 vector2, out PointF point)
        {
            point = Vector2ToPoint(vector2);
        }

        /// <summary>
        /// Converts a XNA color to .Net color.
        /// </summary>
        /// <param name="color">XNA color to convert.</param>
        /// <returns>The created .Net color.</returns>
        public static DotNetColor XnaToDotNetColor(XnaColor color)
        {
            return DotNetColor.FromArgb(
                color.A,
                color.R,
                color.G,
                color.B);
        }

        /// <summary> Converts a specified XNA <see cref="XnaPoint"/> type into
        /// <see cref="Point"/> type.
        /// </summary>
        /// <param name="xnaPoint">
        /// The XNA <see cref="XnaPoint"/> type to convert.
        /// </param>
        /// <returns>The converted <see cref="Point"/> type.</returns>
        public static Point XnaPointToPoint(XnaPoint xnaPoint)
        {
            Point pt = new Point(xnaPoint.X, xnaPoint.Y);
            return pt;
        }

        #endregion public methods

    }
}
